const express = require("express")
const morgan = require("morgan");
const app = express()
const userRouter = require("./routes/ajiaoRouter");

app.use(morgan("dev"));
app.all("*", function (req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header(
    "Access-Control-Allow-Headers",
    "Content-Type,Content-Length, Authorization, Accept,X-Requested-With"
  );
  res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
  res.header("X-Powered-By", " 3.2.1");
  if (req.method == "OPTIONS") res.send(200);
    /*让options请求快速返回*/ else next();
});

app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use("/", userRouter)
app.use(express.static(__dirname + "/public"))


app.set("port", 8001)
app.listen(app.get("port"), () => {
  console.log(`ajiao的服务器正则运行中,http://127.0.0.1:${app.get("port")}`);
});